﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using CodeFarmer.Model.Entities;

namespace CodeFarmer.Model.Mapping
{
    public class ArticleMap : EntityTypeConfiguration<Article>
    {
        public ArticleMap()
        {
            this.HasKey(t => t.ID);

            this.Property(t => t.CreateTime)
                .IsRequired();

            this.Property(t => t.Title)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.Content)
                .IsRequired();

            this.ToTable("Articles");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.AuthorID).HasColumnName("AuthorID");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.Content).HasColumnName("Content");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
            this.Property(t => t.EditTime).HasColumnName("EditTime");
            this.Property(t => t.EnableCommnet).HasColumnName("EnableComment");
            this.Property(t => t.ShowOrder).HasColumnName("ShowOrder");
            this.Property(t => t.UpCount).HasColumnName("UpCount");
            this.Property(t => t.ViewCount).HasColumnName("ViewCount");
            this.Property(t => t.State).HasColumnName("State");

            //this.HasMany(t => t.Comments)
            //    .WithMany(t => t.Articles)
            //    .Map(m =>
            //    {
            //        m.ToTable("ArticleCommentsRelation");
            //        m.MapLeftKey("ArticleID");
            //        m.MapRightKey("CommentID");
            //    });
        }
    }
}
